#/bin/bash

ips="$(cat /root/iplist.txt|awk '{print $2}')"
echo "-------ip------------start time------------online time-------"

for ip in $ips; do
	online_second=$(echo $(ssh root@$ip "cat /proc/uptime")|awk '{print $1}'|awk -F"." '{print $1}')
	online_min=0
	online_hour=0
	online_time="$online_second"
	start_time=$(date -d "$online_second second ago" +"%Y-%m-%d %H:%M:%S")
	if [ $online_second -gt 60 ]; then
		online_min=$(expr $online_second / 60)
		online_second=$(expr $online_second % 60)
		if [ $online_second -lt 10 ]; then
			online_second="0$online_second"
		fi
		online_time="${online_min}:${online_second}"
	fi
	if [ $online_min -gt 60 ]; then
		online_hour=$(expr $online_min / 60)
		online_min=$(expr $online_min % 60)
		if [ $online_hour -lt 10 ]; then
			online_hour="0$online_hour"
		fi
		if [ $online_min -lt 10 ]; then
			online_min="0$online_min"
		fi
		online_time="${online_hour}:${online_min}:${online_second}"
	fi
	printf "%-18s%12s%16s\n" "$ip" "$start_time" "$online_time"
done

